package com.admin.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.util.ArrayList;

/**
 * 自动封装token 到feign请求头中。
 */
@Configuration
public class FeignConfig implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        // 通过请求上下文对象  获取token3
       /* ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token1 =  attributes.getRequest().getHeader("token");*/
       String token="eyJhbGciOiJIUzUxMiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAAADWL0QrDIAwA_yXPFUxnktm_serAQocQhY2xf1_6sLc7jvvAMRpsQIGjL4guS1xdCJ7cThEdlUfOPnqpcocFWhqwITMLoRAvoHO3W9866nl1VdOpLT3N0ixmqXfj-ur_k27X2ayt3x8jtUeigAAAAA.ArSvHY70pNF1yZ4FLu1VPinxWBu4X4C51wrxEoG21QCklVnKzEE3WKa891nZEGGpC6QSaQPP3lGPyeLVSP5k9A";
       requestTemplate.header("token",token);
    }

}
